﻿using DLog.Config;
using DLog.IStorageDal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DLog.StorageFactory
{
    public class StorageFactory
    {
        static IDal DalFactory = null;
        /// <summary>
        /// 获取操作日志的交互接口
        /// </summary>
        /// <param name="DalAssemblyStr"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public static IDal GetStorageDal(string target, string connectionString)
        {
            if (DalFactory == null)
            {
                string DalAssemblyStr = StorageConfig.GetAssembly(target);
                string DalStr = DalAssemblyStr + ".AccessDal";
                object[] ob = new object[] { connectionString };
                DalFactory = (IDal)System.Reflection.Assembly.Load(DalAssemblyStr).CreateInstance(DalStr, false, System.Reflection.BindingFlags.Default, null, ob, null, null);//.CreateInstance(DalStr);
            }
            return DalFactory;
        }
    }
}
